<?php
if (!isset($_POST['title'])) {
	echo "";
	die();
}
$title = $_POST['title'];
$new = $_POST['new'];
$exact = $_POST['exact'];

$vars = parse_ini_file("../ini/settings.ini");
$connect = mysql_connect($vars["mysql_host"],$vars["mysql_username"],$vars["mysql_password"]) or die(mysql_error());
$db = mysql_select_db($vars["mysql_database"],$connect);
if (trim($title) == "") {
	echo "";
	exit;
}
if ($new == 1) {
	if ($exact == 1) {
		$sql = "select title,display_names.display_name,strSplit(display_names.display_name, ' ', 1) as channel, channels.channel_id from listings LEFT JOIN channels ON (listings.channel = channels.channel_id)  left join display_names on (display_names.channel = channels.id) where title=\"$title\" and display_order=0 group by title,display_names.display_name limit 30";
	} else {
		$sql = "select title,display_names.display_name,strSplit(display_names.display_name, ' ', 1) as channel, channels.channel_id from listings LEFT JOIN channels ON (listings.channel = channels.channel_id)  left join display_names on (display_names.channel = channels.id) where title like \"%$title%\" and display_order=0 group by title,display_names.display_name limit 30";
	}
	$result = mysql_query($sql,$connect) or die (mysql_error());
	?>
	<table border="1">
	<?php
	while ($row = mysql_fetch_array($result)) {
		echo "<tr>\n";
		echo "<td><font size=\"2\">".$row[0]."</font></td>\n";
		echo "<td><font size=\"2\">".$row[1]."</font></td>\n";
		$row[0] = addslashes($row[0]);
		echo "<td><input type=\"button\" name=\"record\" id=\"record\" value=\"Record this series\" onClick=\"Record('$row[0]','$row[1]','$row[2]','$row[3]')\"></td>\n";
		echo "</tr>\n";
	}
	?>
	</table>
<?php
} else if ($new == 0) {
	//this will be where we can late record something....
	$sql = "select title,display_names.display_name,strSplit(display_names.display_name, ' ', 1) as channel, channels.channel_id,sub_title,start,end,episode_num_dd_progid,episode_num_onscreen from listings LEFT JOIN channels ON (listings.channel = channels.channel_id) left join display_names on (display_names.channel = channels.id) where title like \"%$title%\" and display_order=0 order by start limit 100";
	$result = mysql_query($sql,$connect) or die (mysql_error());
	?>
	<table border="1">
	<?php
	while ($row = mysql_fetch_array($result)) {
		$s = strtotime($row[5]);
		$start = date("Y-m-d H:i:s",$s);
		$s = strtotime($row[6]);
		$end = date("Y-m-d H:i:s",$s);
		echo "<tr>\n";
		echo "<td><font size=\"2\">".$start."</font></td>\n";
		echo "<td><font size=\"2\">".$row[0]."</font></td>\n";
		echo "<td><font size=\"2\">".$row[1]."</font></td>\n";
		echo "<td><font size=\"2\">".$row[4]."</font></td>\n";
		$row[4] = addslashes($row[4]);
		$row[0] = addslashes($row[0]);
		echo "<td><input type=\"button\" name=\"record_single\" id=\"record_single\" value=\"Record this episode\" onClick=\"RecordSingle('$start','$end','$row[2]','$row[4]','$row[0]','$row[7]','$row[3]','$row[8]')\"></td>\n";
		//echo "<td><input type=\"button\" name=\"record_single\" id=\"record_single\" value=\"Record this episode\" onClick=\"alert('$start $end $row[2] $row[4] $row[0] $row[7] $row[3] $row[8]')\"></td>\n";
		echo "</tr>\n";
	}
	?>
	</table>
	<?php
}
?>
